package com.pospi.pai.yunpos.been;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pospi.modle.GoodsBeen;
import com.pospi.pai.yunpos.R;
import com.pospi.util.DoubleSave;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by acer on 2018/6/19.
 */

public class BillgoodsDetailAdapter extends BaseAdapter {
    private Context context;
    private List<GoodsBeen> goodsDtos;

    public BillgoodsDetailAdapter(Context context, List<GoodsBeen> goodsDtos) {
        this.context = context;
        this.goodsDtos = goodsDtos;
    }

    @Override
    public int getCount() {
        return goodsDtos.size();
    }

    @Override
    public Object getItem(int i) {
        return goodsDtos.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final GoodsBeen dto = goodsDtos.get(i);
        final Holder holder;
        if (view == null) {
            holder = new Holder();
            view = LayoutInflater.from(context).inflate(R.layout.bill_detail_item_re, null);
            holder.code = (TextView) view.findViewById(R.id.tv_item_code);
            holder.name = (TextView) view.findViewById(R.id.tv_item_name);
//            holder.tv_goods_unit = view.findViewById(R.id.tv_goods_unit);
            holder.tv_item_price = view.findViewById(R.id.tv_item_price);
            holder.tv_item_num = view.findViewById(R.id.tv_item_num);
            holder.tv_item_je = view.findViewById(R.id.tv_item_je);
            holder.number = view.findViewById(R.id.item_number);
            holder.yssl = view.findViewById(R.id.tv_item_ysnum);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        holder.number.setText(String.valueOf(i+1));
        holder.code.setText(dto.getBarcode());
        holder.name.setText(dto.getName());
        DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
//        holder.tv_goods_unit.setText(dto.getUnit());
        holder.tv_item_price.setText(dto.getDj() + "/"+dto.getUnit());
        holder.tv_item_num.setText(dto.getSl()+"");
        holder.tv_item_je.setText(DoubleSave.doubleSaveTwo(dto.getSl() * dto.getDj())+"");
        holder.yssl.setText(String.valueOf(dto.getSjsl()));

        return view;
    }
    class Holder{
        TextView code;
        TextView name;
        TextView tv_goods_unit;
        TextView tv_item_num;
        TextView tv_item_price;
        TextView tv_item_je;
        TextView number;
        TextView yssl;
    }
}
